#include <iostream>
#include <algorithm>


int main(){
    int num = 0;
    std::cin >> num;
    int prev = 0, next = 1;
    int nnext = 1;
    while(num < prev || num > next){
        nnext = prev + next;
        prev = next;
        next = nnext;
    }
    std::cout << std::min(next - num, num - prev);
    return 0;
}